﻿using KludgeBox;
using KludgeBox.Events;
using KludgeBox.Net;
using VectorSurvivors.Multiplayer;

namespace VectorSurvivors.GameWorld;

[GameService]
public class GeneralWorldService
{
    public World CurrentWorld { get; private set; }

    [EventListener]
    public void OnRegisterWorldRequest(RegisterWorldRequest worldRegister)
    {
        CurrentWorld = worldRegister.World;
    }

    [EventListener]
    public void OnRequireWorldQuery(RequireWorldQuery worldRequest)
    {
        worldRequest.SetResult(CurrentWorld);
    }

    [EventListener]
    public void OnEntitySpawnRequest(EntitySpawnRequest entitySpawnRequest)
    {
        
    }

    [EventListener]
    public void OnEntityAddRequest(EntityAddRequest request)
    {
        CurrentWorld.AddEntity(request.Entity);
    }

    [EventListener]
    public void OnLocalPlayerSpawnedEvent(LocalPlayerSpawnedEvent playerSpawnedEvent)
    {
        CurrentWorld.Floor.Camera = playerSpawnedEvent.Player.Camera;
    }
}